﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Hangjing.Common;
using Hangjing.SQLServerDAL;
using Hangjing.Model;
using Hangjing.DBUtility;

/// <summary>
///考勤记录
/// </summary>
public partial class qy_54tss_Admin_Sale_attendancelist : System.Web.UI.Page
{
    /// <summary>
    /// 管理员条件
    /// </summary>
    private string SqlWhere
    {
        get
        {
            object o = ViewState["SqlWhere"];
            return (o == null) ? "" : Convert.ToString(o);
        }
        set
        {
            ViewState["SqlWhere"] = value;
        }
    }



    DeliverWorkLog bll = new DeliverWorkLog();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            SqlWhere = "  1=1 ";

            hfyestoday.Value = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
            hftoday.Value = DateTime.Now.ToString("yyyy-MM-dd");

            tbStartTime.Text = DateTime.Now.ToString("yyyy-MM-dd");
            tbEndTime.Text = DateTime.Now.ToString("yyyy-MM-dd");

            InitSqlwhere();
            BindData();
        }
    }

    /// <summary>
    /// 绑定指定的数据
    /// </summary>
    protected void BindData()
    {
        IList<DeliverWorkLogInfo> shops = bll.GetList(AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, SqlWhere, "LID", 1);

        this.AspNetPager1.RecordCount = bll.GetCount(SqlWhere);
        this.rptsum.DataSource = shops;
        this.rptsum.DataBind();

        AlertScript.AjaxRegisterScript("init();", UpdatePanel1);
    }

    protected void btSearch_Click(object sender, EventArgs e)
    {
        InitSqlwhere();
        BindData();
    }

    /// <summary>
    /// 生成查询条件
    /// </summary>
    protected void InitSqlwhere()
    {
        SqlWhere = "  1=1 ";
        SqlWhere = new RightsTool().getDeliverWorkLogWhere(SqlWhere);
        if (this.tbStartTime.Text != "")
        {
            SqlWhere += " and  [optime] > '" + WebUtility.InputText(this.tbStartTime.Text) + "' ";
        }
        if (this.tbEndTime.Text != "")
        {
            SqlWhere += " and optime < '" + WebUtility.InputText(this.tbEndTime.Text) + " 23:59:59'";
        }
        if (tbshopname.Text != "")
        {
            SqlWhere += " and EXISTS(SELECT * FROM dbo.Deliver WHERE DataId = dbo.DeliverWorkLog.deliverid AND Name LIKE '%" + Utils.RegEsc(WebUtility.InputText(this.tbshopname.Text.Trim())) + "%') ";
        }


    }


    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        BindData();
    }


}
